new Vue({
    el: '#app',
    data() {
        return {
            // 菜单
            menu: [
                {class_name: 'icon-datu', text: '大图标'},
                {class_name: 'icon-xiaotu', text: '小图标'},
                /*{class_name: 'icon-liebiao', text: '列表'},*/
                {class_name: 'icon-shuaxin', text: '刷新'},
                {class_name: 'icon-zhongqi', text: '重启录音'},
                /*{class_name: 'icon-xitong', text: '系统管理'},*/
                /*{class_name: 'icon-chaxun', text: '查询'},*/
            ],
            // 当前的obj
            currObj: {},
            result: [],
            ws:{},
            // 列表数据
            listData: [],
            audioArr: [],
            audioArrUrl: [],
            listIdx: 1,
            iconType: 1,
            diskSize: 0,
            diskUsed: 0,
            diskAvail: 0,
            diskUsePercent: 0,
            fpath:'',
            lastTime:'',
            recordTotal:0,
            socket_url:'',
            lockReconnect: false,//是否真正建立连接
            websocketNum:0
        }
    },

    methods: {
        showTitle(item){
            let title
            switch (item.state) {
                case 0:
                    title = '断线'
                    break;
                case 1:
                    title = '空闲'
                    break;
                case 2:
                case 3:
                    title = '摘机'
                    if((item.flag & 1)==1)
                    {
                        title = '录音'
                    }
                    break;
                case 4:
                    title = '禁用'
                    break;
                case 5:
                    title = '振铃'
                    break;
                case 6:
                    title = '拨号'
                    break;
            }
            if((item.flag & 1) && item.state !=0 && item.state !=4){

            }
            else if ((item.flag & 2)&&(item.state !=0 && item.state !=4)){
                title = title+'-监听中'
            }
            return title;
        },
        //刷新录音
        refresh(){
            $("#contenttext").html('正在刷新.')
            $('#myModal').modal('show');
            this.onOpen()
             $('#myModal').modal('hide');

        },
        onClickLeft() {
            Toast('返回');
        },
        onClickRight() {
            Toast('按钮');
        },
        getSocketUrl(url, param) {
            return new Promise((resolve, reject) => {
                axios.get(url, {params: param})
                    .then(response => {
                        resolve(response.data)
                    }, err => {
                        reject(err)
                    })
                    .catch((error) => {
                        reject(error)
                    })
            })
        },
        createChart() {
            // 基于准备好的dom，初始化echarts实例
            //https://www.echartsjs.com/examples/zh/index.html#chart-type-pie
            var myChart = echarts.init(document.getElementById('container'));
            // 绘制图表
            myChart.setOption({
                tooltip: {
                    trigger: 'item',
                    formatter: '{b} : {c} ({d}%)'
                },
                legend: {
                    // orient: 'vertical',
                    // top: 'middle',
                    bottom: 10,
                    left: 'center',
                    data: ['已用空间', '剩余空间']
                },
                series: [
                    {
                        type: 'pie',
                        radius: '65%',
                        center: ['50%', '50%'],
                        selectedMode: 'single',
                        data: [
                            {value: this.diskUsePercent, name: '已用空间'},
                            {value: 100 - this.diskUsePercent, name: '剩余空间'}
                        ],
                        color : [ '#ccc', '#57A1E7'],
                    }
                ]

            });


        },
        getIndexInfo(){
            let obj = {
                token: '020551'
            }
            let url =location.protocol+'//'+location.hostname+':'+location.port+'/home/login/indexInfo'
            this.getSocketUrl(url, obj).then((value)=>{
                var datas = eval('(' + value.recordStatus + ')');
                this.listData = datas
                this.recordTotal = value.recordInfo.recordTotal
                this.lastTime = value.recordInfo.lastTime
                this.diskSize = value.diskSize
                this.diskUsed = value.diskUsed
                this.diskUsePercent = value.diskUsePercent
                this.diskAvail = value.diskAvail
                this.fpath = value.fpath
                this.createChart();
            })

        },
        getinfo(){
            var that = this
            that.getIndexInfo()
            var test2 = setInterval(function () {
                //新连接
                that.getIndexInfo();
            },2000);
        }, 
    },
    mounted() {
        this.$nextTick(() => {
           this.getinfo()
        });
    }
});